home *** CD-ROM | disk | FTP | other *** search
- Path: chewy.vcx.net!usenet
- From: Bruce Arnold <barnold@vcx.net>
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: Q: Time to call a function?
- Date: Mon, 08 Jan 1996 01:48:49 -0800
- Organization: Sprint United Telephone/Eastern - Internet @ccess
- Message-ID: <30F0E881.5F3D@vcx.net>
- References: <4cnjsf$kq0@mark.ucdavis.edu>
- NNTP-Posting-Host: y-wing-2a-4.tatooine.vcx.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b2a (Windows; I; 16bit)
-
- > About how much time does calling a function, allocating memory, and
- > executing simple statements like "i = 3" take?
-
- The Intel programmers reference manual lists the number of clocks for
- each instruction. This varies from about 2 to 250. The above
- assignment statement probably uses a memory MOV which may take 20 clocks
- depending on the processor. A 'CALL' to a subroutine can take over 200.
- Memory allocation might require many CALL's and other instructions
- amounting to perhaps 10,000 to 100,000 clocks.
-
- To get back to 'time' (for the ballpark calculation) note that a
- processor running at 66 MHZ has a clock time of 15 nanoseconds.
- ( 1 / 66,000,000 ). That memory allocation which required 100,000
- clocks will take 1.5 milliseconds. That assignment will take
- 20 * 15ns = 300ns or 0.3 microsecs.
-
- It can be very tedious to try to calculate the exact value by looking
- at the assembly source code; that's what benchmarks are for.
- Note also that in real computers, most of the time is spent doing data
- input / output to storage devices and sending data to the screen.
-
- Bruce.
-